//
//  TJMainController.m
//  CrossBorderPayment
//
//  Created by hc-101 on 2020/6/9.
//  Copyright © 2020 xtjun. All rights reserved.
//

#import "TJMainController.h"
#import "TJBaseController.h"
#import "TJBaseNavController.h"

@interface TJMainController ()

@property (strong, nonatomic) NSArray *tabItemConfigurations;


@end

@implementation TJMainController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self setingTabBar];
    [self addChildViewController];
}

- (void)setingTabBar {
    
    self.tabBar.translucent = NO;
    self.tabBar.barTintColor = UIColor.whiteColor;
    self.tabBar.backgroundColor = UIColor.whiteColor;
    self.tabBar.shadowImage = [UIImage new];

    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, -0.5, KScreenWidth, 0.5)];
       view.backgroundColor = UIColor.tj_separatorColor;
       [[UITabBar appearance] insertSubview:view atIndex:0];
    if (@available(iOS 13.0, *)) {
        [[UITabBar appearance] setTintColor:UIColor_Hex(0x3881E8)];
        [[UITabBar appearance] setUnselectedItemTintColor:UIColor_Hex(0xB6B6B6)];
    } else {
        [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:UIColor_Hex(0xB6B6B6)} forState:UIControlStateNormal];
        [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:UIColor_Hex(0x3881E8)} forState:UIControlStateSelected];
    }
}

 
- (void)addChildViewController {
    [self.tabItemConfigurations enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [self addChildViewController:[[NSClassFromString(obj[@"controllerName"]) alloc] init] image:obj[@"iconName"] title:obj[@"title"]];
    }];
}

- (void)addChildViewController:(UIViewController *)childController image:(NSString *)image title:(NSString *)title {
    TJBaseNavController *navigationController = [[TJBaseNavController alloc] initWithRootViewController: childController];
    navigationController.view.backgroundColor = [UIColor whiteColor];
    [self addChildViewController: navigationController];
    childController.title = title;
    childController.navigationItem.title = title;
    childController.tabBarItem.image = [UIImage imageNamed:image];
    childController.tabBarItem.selectedImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_select", image]];
}


- (NSArray *)tabItemConfigurations {
    if (!_tabItemConfigurations) {
        _tabItemConfigurations = @[
                                   @{
                                       @"controllerName": @"TJHomeController",
                                       @"iconName": @"home",
                                       @"title": @"首页".localizedString
                                       },
                                   @{
                                       @"controllerName": @"TJFriendsController",
                                       @"iconName": @"friend",
                                       @"title": @"朋友".localizedString
                                       },
                                   @{
                                       @"controllerName": @"TJMineController",
                                       @"iconName": @"mine",
                                       @"title": @"我的".localizedString
                                       },
                                   
                                   ];
    }
    return _tabItemConfigurations;
}



@end
